import { getClientList } from '../../../network/client'
import { debounce,Filter } from '../../../utils/Tools'
Page({
  data: {
    clientList:[],
    value:null,
    afterList:[]
  },
  onLoad(){
    this.handleFilter = debounce(this.handleFilter,100)

  },
  onShow(){
    //   调用网络请求
    this._getClientList()
  },
  //       函数事件        //
  async handleFilter(e){
    console.log(e)
    // console.log(this.data.clientList)

    const res = await Filter(e.detail,this.data.clientList)
    // console.log(res)
    this.setData({afterList:res})
  },
  //       网络请求        //
  async _getClientList(){
    const res = await getClientList()
    if(res.code === 200){
      this.setData({
        clientList: res.data,
        afterList: res.data
      })
    }
  },
  containOrder(e){
    let index=e.currentTarget.dataset.index;
    let afterList=this.data.afterList;
    let orderList={};
    console.log(afterList)
    // wx.navigateTo({
    //   url: '/pages/client/valet-order/valet-order?orderList='+orderList
    // })
    wx.request({
      url: 'https://master.gddzxcx.com/api/'+'orders/again_orders',
      data:{
        customer_id:afterList[index].id,
        token:wx.getStorageSync('token')
      },
      success:res=>{
      if(res.data.code===200){
        orderList=JSON.stringify(res.data.data);
        wx.navigateTo({
          url: '/pages/client/valet-order/valet-order?orderList='+orderList,
        })
      }else{
        wx.navigateTo({
          url:'/pages/client/valet-order/valet-order?customer_id='+afterList[index].id+'&supplyer_company='+afterList[index].supplyer_company
        })
      }
        console.log(res)
        orderList=res.data.data;
      },
      fail:err=>{
        console.log(err)
      }
    })
   
  },
});